package com.explodingzombie.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.util.Collection;

public class GeneralUtils {

	public static String inputStreamToString(InputStream inStream, String cs) throws IOException
	{
		StringWriter writer = new StringWriter();
		
		char[] buffer = new char[32 * 1024];
		Reader reader = new BufferedReader(new InputStreamReader(inStream, cs), 1024);
		for(int len = 0; (len = reader.read(buffer)) != -1; ){
			writer.write(buffer, 0, len);
		}
		
		return writer.toString();
	}
	
	public static boolean isEmpty(Object o){
		if(o == null) return true;
		
		if(o instanceof String)
			return ((String)o).length() <= 0;
		
		if(o instanceof Collection)
			return ((Collection)o).size() <= 0;
		
		return false;
	}
	
}
